using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;

using Microsoft.SqlServer.Management.Common;
using System.Collections;

namespace Quanly_dethi.Class
{
    class csC_Trinhdo
    {
        private ketnoi kn;

        public ketnoi Kn
        {
            get { return kn; }
            set { kn = value; }
        }
        private string databasename;

        public string Databasename
        {
            get { return databasename; }
            set { databasename = value; }
        }
        public csC_Trinhdo()
        {
            Kn = new ketnoi();
            databasename = "";
        }
        public csC_Trinhdo(string servername, string user, string pass, string dbname)
        {
            Kn = new ketnoi(servername ,user, pass);
            databasename = dbname;
        }
        public DataTable Sellect()
        { 
            Database db=Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select * from TrinhDo").Tables[0];
        }
        public DataTable Sellect(int id)
        {
            Database db = Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select * from TrinhDo where MaTD=" + "'" + id + "'").Tables[0];
        }
        public ArrayList SellectArr()
        {
            Database db = Kn._Server.Databases[databasename];
            DataTable dt = db.ExecuteWithResults("select MaTD, Trinhdo from TrinhDo").Tables[0];
            ArrayList ar = new ArrayList();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                item t = new item(dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString());
                ar.Add(t);

            }
            return ar;
        }
       
    }
}
